package OrederManagement.command;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import OrederManagement.command.impl.ExitCommand;
import OrederManagement.command.impl.HelpSuperUserCommand;
import OrederManagement.command.impl.SuperUserSelectCommand;
import OrederManagement.pojo.User;

public class SuperUserCommandFactory extends UserCommandFactory {

	private static Map<CommandCode,Class<? extends Command>> superUserMap =new HashMap<>();
	
	static {
		superUserMap.put(CommandCode.HELP, HelpSuperUserCommand.class);
		superUserMap.put(CommandCode.SELECT, SuperUserSelectCommand.class);
		superUserMap.put(CommandCode.EXIT, ExitCommand.class);	
	}
	public SuperUserCommandFactory(User user) {
		super(user);
	}

	@Override
	public Command buildCommand(CommandCode cmdCode) {
		Class<?extends Command> cmdClass =superUserMap.get(cmdCode);
		if(cmdClass==null){
			return super.buildCommand(cmdCode);
		}
		Command command=null;
		try {
			command =cmdClass.getConstructor(User.class).newInstance(getUser());
		} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
				| NoSuchMethodException | SecurityException e) {
			e.printStackTrace();
		}
		
		return command;
	}

}
